home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / kant-generator-04-c / Kant ƒ / Shell ƒ / graphics.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  7.9 KB  |  190 lines  |  [TEXT/MMCC]

  1. #ifndef __GRAPHICS_H__
  2. #define __GRAPHICS_H__
  3.  
  4. #include "QDOffscreen.h"
  5.  
  6. #define MAX_TE_HANDLES 1
  7.  
  8. typedef struct
  9. {
  10.     WindowPtr            theWindowPtr;            /* window ptr of window */
  11.     short                windowIndex;            /* index of window in program's window list */
  12.     short                windowWidth;            /* width of window content, in pixels */
  13.     short                windowHeight;            /* height of window content, in pixels */
  14.     short                windowType;                /* type of window (see IM Essentials, 4-80) */
  15.     short                windowDepth;            /* current pixel depth of window */
  16.     short                maxDepth;                /* maximum pixel depth of window */
  17.     Boolean                hasCloseBox;            /* window has a close box */
  18.     Boolean                offscreenNeedsUpdate;    /* TRUE if offscreen bitmap needs redrawing */
  19.     Boolean                isColor;                /* TRUE if color, FALSE if grayscale */
  20.     Boolean                topLeftInitted;            /* TRUE if top/left coords initted */
  21.     Point                initialTopLeft;            /* initial window bounds when opened */
  22.     Rect                windowBounds;            /* on screen rectangle of window content */
  23.     TEHandle            hTE[MAX_TE_HANDLES];    /* array of textedit handles */
  24.     Str31                windowTitle;            /* pascal string, title of window */
  25. } WindowDataRec, *WindowDataPtr, **WindowDataHandle;
  26.  
  27. typedef short (*dispatchProcPtr)(WindowDataHandle theData, short theMessage, unsigned long misc);
  28.  
  29. typedef struct                                    /* exactly the same as WindowDataRec */
  30. {                                                /* + dispatchProc at end */
  31.     WindowPtr            theWindowPtr;
  32.     short                windowIndex;
  33.     short                windowWidth;
  34.     short                windowHeight;
  35.     short                windowType;
  36.     short                windowDepth;
  37.     short                maxDepth;
  38.     Boolean                hasCloseBox;
  39.     Boolean                offscreenNeedsUpdate;
  40.     Boolean                isColor;
  41.     Boolean                topLeftInitted;
  42.     Point                initialTopLeft;
  43.     Rect                windowBounds;
  44.     TEHandle            hTE[MAX_TE_HANDLES];
  45.     Str31                windowTitle;
  46.     dispatchProcPtr        dispatchProc;            /* called with message of windowish event */
  47. } ExtendedWindowDataRec, *ExtendedWindowDataPtr, **ExtendedWindowDataHandle;
  48.  
  49. enum                    /* messages passed to window's dispatch procedure */
  50. {
  51.     kNull=0,            /* on null event when window is active, frgrnd/bkgrnd */
  52.     kStartup,            /* on program startup */
  53.     kShutdown,            /* on program shutdown */
  54.     kInitialize,        /* just before window is created & shown */
  55.     kOpen,                /* just after window is created & shown */
  56.     kUpdate,            /* during window update -- draw contents to current grafport */
  57.     kClose,                /* just before window is closed -- this can cancel close */
  58.     kDispose,            /* just after window is closed/disposed */
  59.     kActivate,            /* on window activate event */
  60.     kDeactivate,        /* on window deactivate event */
  61.     kSuspend,            /* on program suspension (switched into background) */
  62.     kResume,            /* on program resuming (switching into foreground) */
  63.     kKeydown,            /* on keydown event when window is active & in foreground */
  64.     kMousedown,            /* on mousedown event in window content when active & in frgrnd */
  65.     kUndo,                /* specific to window */
  66.     kCut,
  67.     kCopy,
  68.     kPaste,
  69.     kClear,
  70.     kSelectAll,
  71.     kChangeDepth,        /* offscreen bitmap just created or pixel depth changed */
  72.     kCopybits,            /* actual copybits to update onscreen window from offscreen */
  73.     kDrag,
  74.     kGrow,
  75.     kZoom,
  76.     kGetGrowSize
  77. };
  78.  
  79. enum                    /* return codes from window dispatch procedure */
  80. {
  81.     kSuccess=0,            /* message handled, no further processing please */
  82.     kFailure,            /* message not handled, use default action if any */
  83.     kCancel                /* message refused, cancel action (only good with kClose) */
  84. };
  85.  
  86. #define GetWindowData_windowPtr(x)                ((**(x)).theWindowPtr)
  87. #define GetWindowData_windowIndex(x)            ((**(x)).windowIndex)
  88. #define GetWindowData_windowWidth(x)            ((**(x)).windowWidth)
  89. #define GetWindowData_windowHeight(x)            ((**(x)).windowHeight)
  90. #define GetWindowData_windowType(x)                ((**(x)).windowType)
  91. #define GetWindowData_windowDepth(x)            ((**(x)).windowDepth)
  92. #define GetWindowData_maxDepth(x)                ((**(x)).maxDepth)
  93. #define GetWindowData_hasCloseBox(x)            ((**(x)).hasCloseBox)
  94. #define GetWindowData_offscreenNeedsUpdate(x)    ((**(x)).offscreenNeedsUpdate)
  95. #define GetWindowData_isColor(x)                ((**(x)).isColor)
  96. #define GetWindowData_windowPos(x)                ((**(x)).initialTopLeft)
  97. #define GetWindowData_windowPosInitted(x)        ((**(x)).topLeftInitted)
  98. #define GetWindowData_windowBounds(x)            ((**(x)).windowBounds)
  99. #define GetWindowData_windowBoundsTopLeft(x)    (*((Point*)((**(x)).windowBounds)))
  100. #define GetWindowData_hTE(x, y)                    ((**(x)).hTE[y])
  101. #define GetWindowData_windowTitle(x)            ((**(x)).windowTitle)
  102. #define GetWindowData_dispatchProc(x)            ((**(x)).dispatchProc)
  103.  
  104. #define SetWindowData_windowPtr(x, y)            { (**(x)).theWindowPtr=y; }
  105. #define SetWindowData_windowIndex(x, y)            { (**(x)).windowIndex=y; }
  106. #define SetWindowData_windowWidth(x, y)            { (**(x)).windowWidth=y; }
  107. #define SetWindowData_windowHeight(x, y)        { (**(x)).windowHeight=y; }
  108. #define SetWindowData_windowType(x, y)            { (**(x)).windowType=y; }
  109. #define SetWindowData_windowDepth(x, y)            { (**(x)).windowDepth=y; }
  110. #define SetWindowData_maxDepth(x, y)            { (**(x)).maxDepth=y; }
  111. #define SetWindowData_hasCloseBox(x, y)            { (**(x)).hasCloseBox=y; }
  112. #define SetWindowData_offscreenNeedsUpdate(x,y)    { (**(x)).offscreenNeedsUpdate=y; }
  113. #define SetWindowData_isColor(x, y)                { (**(x)).isColor=y; }
  114. #define SetWindowData_windowPos(x, y)            { (**(x)).initialTopLeft=y; }
  115. #define SetWindowData_windowPosInitted(x, y)    { (**(x)).topLeftInitted=y; }
  116. #define SetWindowData_windowBounds(x, y)        { (**(x)).windowBounds=y; }
  117. #define SetWindowData_hTE(x, y, z)                { (**(x)).hTE[y]=z; }
  118. #define SetWindowData_windowTitle(x, y)            { Mymemcpy((Ptr)(**(x)).windowTitle, (Ptr)y, y[0]+1); }
  119. #define SetWindowData_dispatchProc(x, y)        { (**(x)).dispatchProc=y; }
  120.  
  121. #define GetWindowIndex(x)        GetWindowData_windowIndex(x)
  122.  
  123. #define GetWindowPtr(x)            GetWindowData_windowPtr(x)
  124. #define GetIndWindowPtr(x)        GetWindowData_windowPtr(GetWindowDataHandle(x))
  125.  
  126. #define GetOffscreenPtr(x)    \
  127.     (gHasColorQD ?  (WindowPtr)gTheGWorld[GetWindowData_windowIndex(x)] : \
  128.                     (WindowPtr)gBWGrafPtr[GetWindowData_windowIndex(x)])
  129. #define GetIndOffscreenPtr(x)    \
  130.     (gHasColorQD ? (WindowPtr)gTheGWorld[x] : (WindowPtr)gBWGrafPtr[x])
  131.  
  132. #define GetIndWindowPos(x)    \
  133.     GetWindowData_windowPos(GetWindowDataHandle(x))
  134.  
  135. #define GetIndWindowPosInitted(x)    \
  136.     GetWindowData_windowPosInitted(GetWindowDataHandle(x))
  137.  
  138. #define SetIndWindowPos(x, y)    \
  139.     SetWindowData_windowPos(GetWindowDataHandle(x), y)
  140.  
  141. #define SetIndWindowPosInitted(x, y)    \
  142.     SetWindowData_windowPosInitted(GetWindowDataHandle(x), y)
  143.  
  144. #define SetIndWindowTitle(x, y)    \
  145.     SetWindowData_windowTitle(GetWindowDataHandle(x),  y)
  146.  
  147. #define WindowExistsQQ(x)            (GetWindowPtr((x))!=0L)
  148. #define IndWindowExistsQQ(x)        (GetIndWindowPtr((x))!=0L)
  149.  
  150. #define ForceUpdateTheWindow(x)        \
  151.     {    SetWindowData_offscreenNeedsUpdate(x, TRUE);    \
  152.         UpdateTheWindow((ExtendedWindowDataHandle)(x));    }
  153.  
  154. #define ForceUpdateTheIndWindow(x)    \
  155.     ForceUpdateTheWindow(GetWindowDataHandle(x))
  156.  
  157. #define CloseTheIndWindow(x)        \
  158.     CloseTheWindow(GetWindowDataHandle(x))
  159.  
  160. #define GetWindowDepth(x)            \
  161.     GetIndWindowDepth(GetWindowData_windowIndex(x))
  162.  
  163. #define CallIndDispatchProc(x, y, z)    \
  164.     CallDispatchProc(GetWindowDataHandle(x), (y), (z))
  165.  
  166. #define SetIndDispatchProc(x, y)    \
  167.     SetWindowData_dispatchProc(GetWindowDataHandle(x), y)
  168.  
  169. /***************************************************************************************/
  170.  
  171. Boolean InitTheGraphics(void);
  172. void ShutDownTheGraphics(void);
  173. OSErr OpenTheIndWindow(short index);
  174. void GetMainScreenBounds(void);
  175. short GetIndWindowDepth(short index);
  176. short GetBiggestDeviceDepth(ExtendedWindowDataHandle theData);
  177. Boolean WindowIsColor(ExtendedWindowDataHandle theData);
  178. void UpdateTheWindow(ExtendedWindowDataHandle theData);
  179. Boolean CloseTheWindow(ExtendedWindowDataHandle theData);
  180. PicHandle DrawThePicture(PicHandle thePict, short whichPict, short x, short y);
  181. PicHandle ReleaseThePict(PicHandle thePict);
  182. short CallDispatchProc(ExtendedWindowDataHandle theData, short theMessage,
  183.     unsigned long misc);
  184. void KillOffscreen(short index);
  185. ExtendedWindowDataHandle GetWindowDataHandle(short index);
  186. Point GetWindowBoundsTopLeft(WindowDataHandle theData);
  187. GrafPtr GetOffscreenPtrFunction(WindowDataHandle theData);
  188.  
  189. #endif
  190.